<template>
  <div class="box">
    <header class="header">
        <van-nav-bar
          title="订单编辑"
          left-arrow
          @click-left="$router.back()"
        />
    </header>
    <div class="content">
      <van-address-edit
        :area-list="areaList"
        show-postal
        show-set-default
        show-search-result
        :search-result="searchResult"
        :area-columns-placeholder="['请选择', '请选择', '请选择']"
        @save="onSave"
      />
    </div>
  </div>
</template>

<script>
import Vue from 'vue'
import Cookies from 'js-cookie'
import areaList from '../data/areaData.js'
import { AddressEdit, Toast, Area, NavBar } from 'vant'
import { setAddress } from '../../api/index.js'

Vue.use(Area)
Vue.use(AddressEdit)
Vue.use(NavBar)
export default {
  data () {
    return {
      areaList,
      searchResult: []
    }
  },
  methods: {
    // 添加地址
    onSave (content) {
      const { name, tel, province, country, city, county, addressDetail, isDefault, postalCode } = content
      const arr = []
      console.log(content)
      arr.push({
        name: name,
        tell: tel,
        province: province,
        country: country,
        city: city,
        county: county,
        addressDetail: addressDetail,
        isDefault: isDefault,
        postalCode: postalCode
      })
      setAddress({
        userId: Cookies.get('userId'),
        userMsg: arr
      }).then(res => {
        Toast({
          message: '保存成功',
          onClose: () => {
            this.$router.push('/address')
          }
        })
      })
    }
  }
  // mounted () {
  //   if (this.$route.params.id) {
  //   }
  // }
}
</script>

<style>
</style>
